package com.framework.modules.live.dao;

import com.framework.modules.base.entity.SetteleLiveRewardsEntity;
import com.framework.modules.base.entity.StatLiveRewardsEntity;
import com.framework.modules.live.entity.LiveRewardsEntity;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 收礼记录 
 * 
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-11-03 14:35:33
 */
public interface LiveRewardsDao extends BaseMapper<LiveRewardsEntity> {

    List<SetteleLiveRewardsEntity> selectLiveRewardsSetteleEntity();

    /**
     * 查询榜单 周榜 月榜 总榜
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT tlr.uid,tlr.from_uid,tui.avanta,tui.nickname,sum(tlr.object_value) total_coin FROM tb_live_rewards tlr " +
            "left JOIN tb_user_info tui on tui.uid=tlr.from_uid where adddate between #{startTime} and #{endTime} GROUP BY tlr.from_uid,tlr.uid order by total_coin desc ")
    List<StatLiveRewardsEntity> statLiveRewardsTopList(@Param("startTime") Integer startTime,@Param("endTime") Integer endTime);


    /**
     * 查询榜单 全平台小时榜
     * @param startTime
     * @param endTime
     * @return
     */
    @Select("SELECT tlm.uid,tui.avanta,tui.nickname,sum(tlr.object_value) total_coin FROM tb_live_room tlm " +
            " left JOIN tb_user_info tui on tui.uid=tlm.uid " +
            " left join tb_live_rewards tlr on tlm.live_round_id=tlr.live_round_id " +
            " where tlm.state=1 and tlr.adddate between #{startTime} and #{endTime}" +
            " GROUP BY tlr.live_round_id order by total_coin desc ")
    List<StatLiveRewardsEntity> statLiveRewardsTopListToHour(@Param("startTime")Integer startTime,@Param("endTime") Integer endTime);



    /**
     * 查询本场直播打赏榜单
     * @param liveRoundId 直播场次
     * @return
     */
    @Select("SELECT tlr.uid,tlr.from_uid,tui.avanta,tui.nickname,sum(tlr.object_value) total_coin  FROM tb_live_rewards tlr  " +
            "left JOIN tb_user_info tui  on tui.uid=tlr.from_uid where tlr.live_round_id=#{liveRoundId} " +
            "GROUP BY tlr.from_uid order by total_coin desc limit 10 ")
    List<StatLiveRewardsEntity> getRewardsTopList(@Param("liveRoundId") String liveRoundId);

}
